package com.appspot.showup_app.showup;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.SimpleTimeZone;
import java.util.TimeZone;

/**
 * Created by YOTAM on 12/6/2014.
 */
public class DateTimeUtil {

    public static Date fromTimestamp(long timestamp) {
        Calendar cal = Calendar.getInstance(SimpleTimeZone.getTimeZone("Asia/Jerusalem"));
        cal.setTimeInMillis(timestamp * 1000);
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
        return cal.getTime();
    }

    public static String dayOfWeekStr(Date date) {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Jerusalem"));
        DateFormat dfm = new SimpleDateFormat("EEEE");
        return dfm.format(date);
    }

    public static String dateStr(Date date) {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Jerusalem"));
        DateFormat dfm = new SimpleDateFormat("d MMMM");
        return dfm.format(date);
    }

    public static String hoursStr(Date date) {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Jerusalem"));
        DateFormat dfm = new SimpleDateFormat("HH:mm");
        return dfm.format(date);
    }

    public static Long getTimestamp() {
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
        return new Date().getTime() / 1000;
    }
    public static Long getTimestamp(Date date) {
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
        return date.getTime()/ 1000;
    }
}
